<template>
	<view>
		
		
		<view v-if="show==0">
		
		<view class="inputbox">
			<view class="inputbox1">名称</view>
			<view class="inputbox2">
				<input type="text" @input="getname" placeholder="请输入">
			</view>
		</view>
		
		<view class="inputbox">
			<view class="inputbox1">联系电话</view>
			<view class="inputbox2">
				<input type="number" @input="getmobile" maxlength="11" placeholder="请输入">
			</view>
		</view>
		
		<view class="inputbox">
			<view class="inputbox1">区域</view>
			<view class="inputbox2">
				<picker @change="bindPickerChange" range-key="name" :range="address">
					{{city?city:'请选择'}}  
				</picker> 
			</view>
		</view>
	
		
		<view class="titlebox">
			身份证 <text> (国徽页) </text>
		</view>
		
		<view class="imagebox">
			<image class="imageboxup"  @tap="beforeUpload1" :src="[imga?imga:'/static/image/noimg.png']"></image>
		</view>
		
		<view class="titlebox">
			身份证 <text> (头像页) </text>
		</view>
		
		<view class="imagebox">
			<image class="imageboxup"  @tap="beforeUpload2" :src="[imgb?imgb:'/static/image/noimg.png']"></image>
		</view>
		
		<view class="fabu" @tap="submits">提交信息</view>
		<view class="kaitong">
			<text class="icon-wancheng iconfont" @tap="setstatus0" v-if="status==1"></text>
			<text class="icon-xuanzekuangmoren iconfont" @tap="setstatus1" v-if="status!=1"></text>
			 知悉并同意 <text class="cicons" @tap="seexieyi" >《合伙人权益》</text> 
		</view>
		
		
		</view>
		
		<view class="ssz" v-if="show==2">
			<image src="/static/image/ssz.png" mode=""></image>
			<view>审核中...</view>
		</view>
		
		
		<view style="height: 10rpx;"></view>
	</view>
</template>

<script>
	
	import {curl} from 'common/api.js';
	import {baseUrl} from "common/config.js";
	export default {
		data() {
			return {
				imgb:'',
				imga:'',
				status:0,
				address:[],
				city:'',
				city_id:'',
				mobile:'',
				name:'',
				show:0
			}
		},
		
		onLoad() {
			var that=this;
			
			curl('index/getaddress', {}).then((res) => {
				console.log('地址信息',res.data);
				that.address=res.data
			});
		},
		
		onShow() {
			
			// 查看是否已经申请过了 
			var that=this;
			curl('daili/isdiali', {}).then((res) => {
				
				var status=res.data.status;
			
				if (status==1) {
					uni.reLaunch({
						url:"/pages/down/order"
					})
				}	
				this.show=res.data.status;
				
				
				
			});
		},
		
		methods: {
			
			submits(){
				var that=this;
				var status=this.status;
				if (status!=1) {
					uni.showToast({
						title:'请阅读并同意合伙人权益!',
						icon:'none'
					})
					return false;
				}
				
				var name=this.name;
				var mobile=this.mobile;
				var city_id=this.city_id;
				var imgb=this.imgb;
				var imga=this.imga;
				
				
				curl('daili/dailiapply',
				{name:name,mobile:mobile,city_id:city_id,imgb:imgb,imga:imga}).then((res) =>{
					console.log('地址信息',res.data);
					
					uni.showToast({
						icon:'none',
						title:res.msg
					})
					that.address=res.data
				});
				
			},
			
			setstatus1(){
				console.log('0000000')
				this.status=1
			},
			setstatus0(){
				this.status=0
			},
			seexieyi(){
				uni.navigateTo({
					url:'/pages/down/xieye'
				})
			},
			
			getname(ret){
				this.name=ret.detail.value;
			},
			getmobile(ret){
				this.mobile=ret.detail.value;
			},
			
			bindPickerChange(ret){
				console.log(ret);
				var i=ret.detail.value;
				var that=this;
				var address=this.address;
				
				this.city=address[i].name;
				this.city_id=address[i].id;
				
				
				
			},
			
			
			beforeUpload2(){
				var that=this;
				var token = uni.getStorageSync('token');
				
				var imgs=this.imgs;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function (res) {
						var ss=res.tempFilePaths;
						that.imgurl=ss[0];
						uni.uploadFile({
							url: `${baseUrl}`+'common/upload',
							filePath: ss[0], // 本地上传完成后的路径
							name: 'file', 
							formData: {},
							header:{"token": token},
							success: function(uploadFileRes) {
								var ret=JSON.parse(uploadFileRes.data);
								that.imgb=ret.data.fullurl
							}
						});
					
					}
				});
			},
			
			// 上传图片
			beforeUpload1(types) {
				var that=this;
				var token = uni.getStorageSync('token');
				console.log(types);
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function (res) {
						var ss=res.tempFilePaths;
						that.imgurl=ss[0];
						uni.uploadFile({
							url: `${baseUrl}`+'common/upload',
							filePath: ss[0], // 本地上传完成后的路径
							name: 'file', 
							formData: {},
							header:{"token": token},
							success: function(uploadFileRes) {
								var ret=JSON.parse(uploadFileRes.data);
								
								console.log(ret.data.fullurl)
								that.imga=ret.data.fullurl
							}
						});
					
					}
				});
			},
					
		}
	}
</script>

<style>
	
	.ssz>view{
		width: 100%;line-height: 150rpx;
		text-align: center;font-size: 28rpx;color: #666666;
	}
	.ssz>image{
		width: 400rpx;height: 400rpx;margin-top: 200rpx;
	}
	.ssz{
		width: 400rpx;height: 600rpx;margin: auto;
	}
	
	.kaitong>.iconfont{
		margin-right: 5rpx;font-size: 28rpx;
	}
	.icon-wancheng{
		color: #08b059;
	}
	.cicons{
		color: #08b059;
	}
	.kaitong{
		width: 700rpx;height: 90rpx;
		line-height: 90rpx;margin: auto;
		font-size: 28rpx;color: #666666;font-weight: 500;
	}
	.imageboxs{
		width: 700rpx;height: auto;margin: auto;
		display: flex;flex-wrap: wrap;
	}
	.imageboxup{
		width: 162rpx;height: 161rpx;margin-right: 12rpx;margin-bottom: 15rpx;
	}
	.imagebox{
		width: 700rpx;height: 210rpx;margin: auto;
		display: flex;align-items: center;
	}
	.textbox>textarea{
		padding: 10rpx;width: 680rpx;height: 180rpx;
	}
	.textbox{
		width: 700rpx;height: 200rpx;margin: auto;
		background: #fafafa;border-radius: 10rpx;
		border:1px solid #fafafa;
	}
	.titlebox>text{
		color: #666666;font-size: 26rpx;margin-left: 10rpx;
	}
	.titlebox{
		width: 700rpx;margin: auto;
		height: 90rpx;line-height: 90rpx;
		font-size: 30rpx;color: #000000;
	}
	.inputbox2>picker{
		font-size: 28rpx;font-weight: 500;color: #333333;
	}
	.inputbox2{
		width: 500rpx;text-align: right;
		font-size: 28rpx;font-weight: 500;color: #333333;
	}
	.inputbox1{
		width: 200rpx;height: 40rpx;
		font-size: 28rpx;font-weight: 500;color: #333333;
	}
	.inputbox{
		width: 700rpx;height: 100rpx;margin: auto;
		border-bottom: 1px solid #ececec;
		display: flex;align-items: center;justify-content: space-between;
	}
	
.fabu{
	width: 700rpx;height: 70rpx;background: #08b059;
	text-align: center;line-height: 70rpx;
	margin:20rpx auto;border-radius: 70rpx;
	color: #ffffff;
}
</style>
